package p.jce.cert;

import java.security.InvalidAlgorithmParameterException;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.Provider;
import java.security.cert.CertStore;
import java.security.cert.CertStoreParameters;
import java.security.cert.CertStoreSpi;

import p.jce.BC;

public class RCertStore {
	private static final class X extends CertStore {

		protected X(CertStoreSpi storeSpi, Provider provider, String type, CertStoreParameters params) {
			super(storeSpi, provider, type, params);
		}
	}

	public static CertStore getInstance(String algorithm, CertStoreParameters p, Provider provider)
			throws NoSuchAlgorithmException, InvalidAlgorithmParameterException {

		return CertStore.getInstance(algorithm, p, provider);
	}

	public static CertStore getInstance(String algorithm, CertStoreParameters p, String provider)
			throws NoSuchAlgorithmException, NoSuchProviderException, InvalidAlgorithmParameterException {
		if ("BC".equals(provider)) {
			try {
				return new X((CertStoreSpi) BC.newInstance("CertStore", algorithm), null, algorithm, p);
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return CertStore.getInstance(algorithm, p, provider);
	}

	public static CertStore getInstance(String algorithm, CertStoreParameters p) throws NoSuchAlgorithmException,
			InvalidAlgorithmParameterException {
		return CertStore.getInstance(algorithm, p);
	}
}
